<template>
	<view>
		<!-- <comlist title="创建干预方案" :listtitle="listtitle" :listLabel="listLabel" @comSearch="comSearch" :nullData="nullData" :list="list" :options="options" :addpageUrl="'/pages/quickly/Intervention/createIntervention'" @bindClick="bindClick" @jump="jump"></comlist> -->
		<publicList :list="list" :addpageUrl="'/pages/quickly/Intervention/createIntervention'" @detail='detail' @search="search"  :options="options" :nullData="nullData" @bindClick="bindClick"></publicList>
		<u-modal v-model="showModal" :show-cancel-button="true" @confirm="Modalconfirm" :content="showContent"></u-modal>
	</view>
</template>

<script>
import publicList from '@/components/publicList/index.vue'	
import {filterData2} from '@/static/js/filter.js'
export default{
	components:{publicList},
	data() {
		return {
			list: null,
			options: [{
				text: '删除',
				style: {
					backgroundColor: '#EE2437' ,// 删除按钮背景  红的
				}
			}],
			listtitle:'干预方案',
			listLabel:[
				{
					name:'方案编号：',
					key:'schemeNumber'
				},
				{
					name:'签发时间：',
					key:'updateTime'
				},
			],
			showModal:false,
			showContent:'',
			page: 1,
			nullData:false,
			deleteList: '',
			searchVal:''
		}
	},
	onLoad() {
		this.getlist({pageSize:10,pageIndex:1})
	},
	onReachBottom(){
		if(this.nullData == true){
			return;
		}
		this.page = this.page + 1
		this.getlist({pageSize:10,pageIndex:this.page,name:this.name,userName:this.searchVal})
	},
	methods:{
		search(e) {
			this.page = 1
			this.nullData = false
			this.searchVal = e
			this.$api.interveneSchemeList({pageSize:10,pageIndex:1,userName:e}).then(res=>{
				var data =  res.data.result && res.data.result.list.map((a)=>{
					a.updateTime = a.updateTime ? this.filterData2(a.updateTime) : ''
					return a
				})|| []
				this.list = data
				if(this.list.length >= res.data.result && res.data.result.totalCount){
					this.nullData = true;
				}
			})
		},
		filterData2,
		getlist(data){
			const _this = this;
			_this.$api.interveneSchemeList(data).then(res=>{
				var data = res.data.result && res.data.result.list.map((a)=>{
					a.updateTime = a.updateTime ? _this.filterData2(a.updateTime) : ''
					return a
				}) || []
				if(_this.deleteList == 1) {
					_this.list = []
					_this.list = data
					_this.deleteList = ''
				}else {
					_this.list = _this.list ? _this.list.concat(data) : data
					if(_this.list.length >= res.data.result.totalCount){
						_this.nullData = true;
					}
				}
			})
		},
		bindClick(e){
			this.showModal = true
			this.showContent = '是否删除此干预方案'
			this.delItem = e
			// UserInfodelete
		},
		Modalconfirm(){
			this.$api.InterveneSchemedelete(this.delItem.id).then((res)=>{
				if(res.data.returnCode == 200){
					uni.showToast({
						title:'删除成功',
						icon:'none'
					})
					this.page = 1
					this.deleteList = 1;
					this.nullData = false;
					this.getlist({pageIndex:1,pageSize:10,userName:this.searchVal})
				}
			})
		},
		detail(item){
			!item.status || item.status == 1?
				uni.navigateTo({url:encodeURI('/pages/quickly/Intervention/createIntervention?id='+item.id+'&userId='+item.userId+'&userName='+item.realName)})
			:
				uni.navigateTo({url:'/pages/quickly/Intervention/toView?id='+item.id+'&userId='+item.userId+'&userName='+item.realName})
		}
	}
}
</script>

<style>
	
</style>
